package com.hzit.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
//@EnableSwagger2 //swagger3版本不需要使用这个注解，当然写上也无所谓~
@EnableOpenApi
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)  // swagger2版本这里是DocumentationType.SWAGGER_2
                .apiInfo(apiInfo())
                .select()
                // .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                //此包路径下的类，才生成接口文档
                .apis(RequestHandlerSelectors.basePackage("com.hzit"))
                //加了ApiOperation注解的类，才生成接口文档
                // .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
                // .securitySchemes(Collections.singletonList(securityScheme()));
    }
 
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("合众管理平台")
                .description("合众管理平台 API接口文档")
                .license("合众有限公司")
                .licenseUrl("http://hzit.com")
                .version("1.0")
                .build();
    }
}